<?php

try
{

require_once 'core.php';
require_once cf\Config::path.'api/admin.php';

$view = cf\api\admin\getView( cf\param::get('vid') );
$aid = cf\param::get('aid');
$k = cf\param::exist('k') ? cf\param::get('k') : array();

if (cf\param::exist('do'))
{
	$params = array_merge(cf\param::get('p'), $k);
	$do = cf\param::get('do');
	$fileURLs = cf\param::get('URL',array());
	foreach ($fileURLs as $fnm => $url) {
		if ($url) {
			$_FILES[$fnm] = array('name'=>$url, 'type'=>'url');
		}
	}
	if (function_exists('do_edit_save')) {
		do_edit_save($aid,$params);
	} else {
		cf\api\admin\doAction($aid, $params);
	}
	if ('save' == $do) {
		forward( cf\param::get('referer') );
	}
}

$action = cf\api\admin\getAction($aid, $k);

$smarty->assign('k', json_encode($k));
$smarty->assign('view', $view);
$smarty->assign('action', $action);
$smarty->assign('referer', cf\param::get('referer'));
$smarty->assign('goTab', cf\param::get('tab',0));

$name = $k ? cf\api\admin\getNameByKey($view['id'], $k[$view['primary_key_field']]) : false;

if (function_exists('do_edit_create')) {
	do_edit_create($k);
}

show(
	isset($tpl) ? $tpl : 'edit',
	$view['name'].($name ? ": $name":'').' - '.$action['name']
);
}
catch(Exception $e)
{
	echo $e;
}
?>